package com.tianji.promotion.controller;



import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponDiscountDTO;
import com.tianji.promotion.domain.dto.OrderCourseDTO;
import com.tianji.promotion.domain.vo.CouponVO;
import com.tianji.promotion.query.UserCouponQuery;
import com.tianji.promotion.service.IUserCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户领取优惠券的记录，是真正使用的优惠券信息 前端控制器
 * </p>
 *
 * @author lcm
 * @since 2023-08-03
 */
@RestController
@Api(tags = "用户优惠券相关接口")
@RequestMapping("/user-coupons")
@RequiredArgsConstructor
public class UserCouponController {
    private final IUserCouponService userCouponService;



    @PostMapping("/{id}/receive")
    @ApiOperation("领取优惠券")
    public void receiveCoupon(@ApiParam("优惠券id") @PathVariable Long id){
        userCouponService.receiveCoupon(id);
    }

    @PostMapping("/{code}/exchange")
    @ApiOperation("兑换兑换码")
    public void exchangeCoupon(@PathVariable("code") String code){
        userCouponService.exchangeCoupon(code);
    }

    @GetMapping
    @ApiOperation("分页查询我的优惠券")
    public PageDTO<CouponVO> pageCouponVO(UserCouponQuery query){
        return userCouponService.pageCoupon(query);
    }

    @PostMapping("/available")
    @ApiOperation("查询我的优惠券可用方案")
    public List<CouponDiscountDTO> findDiscountSolution(@RequestBody List<OrderCourseDTO> oList){
        return userCouponService.findSolution(oList);
    }

}
